/**
 * 
 */
package std.game.objects.alive

import org.easymock.classextension.MockClassControl
import org.easymock.MockControl
import org.groovymud.object.registry.MudObjectAttendant
import org.groovymud.shell.command.CommandInterpreter
import org.groovymud.shell.command.handler.CommandException;
import org.groovymud.object.registry.Registry
import org.groovymud.object.MudObject
import groovy.util.ResourceException
import org.groovymud.object.registry.InventoryHandler

import std.game.behaviours.Behaviour;
/**
 * @author corbym
 *
 */
public class MOBImplTest extends GroovyTestCase{
	
	/* (non-Javadoc)
	 * 
	 * @see std.game.objects.alive.MOBImpl#initialise()
	 */
	final void testInitialise(){
		MOBImpl mob = new MOBImpl(name:"mob", shortNames:["mob"])
		boolean called = false
		Registry reg = new Registry(null){
					public boolean contains(MudObject object) {false
					};
				}
		
		Behaviour behaviour = [doBehaviour: {arg, arg2 -> assertEquals mob, arg}] as Behaviour
		mob.initialBehaviours = [behaviour]
		mob.setRegistry(reg)
		mob.initialise()
		
		
	}
	
	
	final void testInvokeMissingMethod() {
		MOBImpl testSubject = null
		MockControl attCtrl = MockClassControl.createControl(Registry, [InventoryHandler] as Class[], [null] as Object[])
		Registry reg = (Registry) attCtrl.getMock();
		
		reg.update testSubject
		attCtrl.setDefaultVoidCallable();
		attCtrl.replay();
		
		MockControl interpCtrl = MockClassControl.createControl(CommandInterpreter,[Registry, MudObjectAttendant] as Class[], [null, null] as Object[] );
		CommandInterpreter interp = (CommandInterpreter) interpCtrl.getMock();
		InventoryHandler handler = new InventoryHandler()
		testSubject = new MOBImpl(interpreter:interp, registry: reg, name:"brian rat")
		testSubject.setInventoryHandler handler
		interp.doCommand("north", null, testSubject)
		interpCtrl.setDefaultReturnValue(testSubject)
		interpCtrl.replay();
		
		testSubject.north()
		
		attCtrl.verify()
		interpCtrl.verify()
		
	}
	final void testInvokeMissingMethodException() {
		MOBImpl testSubject = null
		MockControl attCtrl = MockClassControl.createControl(Registry, [InventoryHandler] as Class[], [null] as Object[])
		Registry reg = (Registry) attCtrl.getMock();
		
		reg.update(testSubject);
		attCtrl.setDefaultVoidCallable();
		attCtrl.replay();
		
		MockControl interpCtrl = MockClassControl.createControl(CommandInterpreter,[Registry, MudObjectAttendant] as Class[], [null, null] as Object[] );
		CommandInterpreter interp = (CommandInterpreter) interpCtrl.getMock();
		InventoryHandler handler = new InventoryHandler()
		testSubject = new MOBImpl(inventoryHandler: handler, interpreter:interp, registry: reg, name:"brian rat")
		
		interp.doCommand("north", null, testSubject)
		interpCtrl.setDefaultThrowable(new CommandException("barf", null))
		interpCtrl.replay();
		try{
			testSubject."north"()
			fail("should throw missing method exception")
		}catch(MissingMethodException e){
			
		}
		attCtrl.verify()
		interpCtrl.verify()
		
	}
	
}
